package com.hhh.sun.controller;

import com.hhh.sun.pojo.entity.TbOrder;
import com.hhh.sun.service.OrderService;
import com.hhh.sun.vo.req.OrderAddVo;
import com.hhh.sun.vo.resp.OrderResVo;
import com.hhh.sun.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单操作接口
 */
@Api(value = "/sun", tags = {"订单操作接口"})
@RestController
@RequestMapping("/sun")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 预约订单
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OrderAddVo", name = "vo", value = "", required = true)
    })
    @ApiOperation(value = "预约订单", notes = "预约订单", httpMethod = "POST")
    @PostMapping("/order")
    public R<OrderResVo> preview(@RequestBody OrderAddVo vo){
        return orderService.preview(vo);
    }
    /**
     * 查询一个用户的所有订单
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "userName", value = "", required = true)
    })
    @ApiOperation(value = "查询一个用户的所有订单", notes = "查询一个用户的所有订单", httpMethod = "GET")
    @GetMapping("/order/{userName}")
    public R<List<TbOrder>> getOrderByUserName(@PathVariable("userName")String userName){
        return orderService.getInfoByUserName(userName);
    }
    /**
     * 开始充电
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "orderId", value = "", required = true)
    })
    @ApiOperation(value = "开始充电", notes = "开始充电", httpMethod = "POST")
    @PostMapping("/order/{orderId}")
    public R<Object>start(@PathVariable("orderId")Integer orderId){
        return orderService.start(orderId);
    }

}
